package test3

import java.util

/**
  * Created by Bane.Shi.
  * Copyright MoenSun
  * User: Bane.Shi
  * Date: 2017/8/7
  * Time: 21:03
  */
sealed trait List[+A];
case object Nil extends List[Nothing]
case class Cons[+A](head:A,tail:List[A]) extends List[A]

object List {


  def sum(ints:List[Int]) :Int = ints match {
    case Nil => 0
    case Cons(x,xs) => x+sum(xs)
  }

  def product(ds:List[Double]):Double = ds match {
    case Nil => 1.0
    case Cons(0.0,_) => 0.0
    case Cons(x,xs) => x * product(xs)
  }

  def apply[A](as: A*):List[A] =
    if (as.isEmpty) Nil
    else Cons(as.head,apply(as.tail: _*))

  def main(args:Array[String]):Unit={
    val ls:List[Int] = List(1,3,4)
    println(ls)
  }

}
